package com.youkeyi.ddy.cloud.common.api.application.system.login;

import com.youkeyi.ddy.cloud.common.api.application.system.login.dto.AppletLoginAuthCloudDto;
import com.youkeyi.ddy.cloud.common.api.application.system.login.dto.OfficialLoginAuthCloudDto;
import com.youkeyi.ddy.cloud.common.api.application.system.login.param.AppletLoginAuthCloudParam;
import com.youkeyi.ddy.cloud.common.api.application.system.login.param.OfficialLoginAuthCloudParam;
import com.youkeyi.ddy.cloud.common.response.ResponseContent;
import com.youkeyi.ddy.cloud.common.response.ResponseObjectContent;
import io.swagger.annotations.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 公众号登录授权相关接口
 *
 * @Author liuxiawang
 * @Date 2023-02-16 11:37
 * @Location shenzhen.china
 */
@Api(tags = {"【Official】Login"})
@RestController
@RequestMapping("/system/official/login")
@FeignClient(value = "YOUKEYI-DDY-CLOUD-APPLICATION-SYSTEM", fallback = SystemOfficialLoginFeignServiceFallback.class)
public interface SystemOfficialLoginFeignService {

    /**
     * 微信小程序授权登陆.
     *
     * @return the auth code
     */
    @GetMapping("/getPageUrl")
    @ApiOperation(value = "公众号授权登陆页面URL", authorizations = {@Authorization("com.youkeyi.ddy.cloud.common.api.application.system.login.SystemOfficialLoginFeignService.getPageUrl")})
    @ApiResponse(code = 200, message = "data Property in Response Body", response = AppletLoginAuthCloudDto.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "param", paramType = "query"),
    })
    public abstract OfficialLoginAuthCloudDto getPageUrl(OfficialLoginAuthCloudParam param);

    /**
     * 微信小程序授权登陆轮询.
     *
     * @return the auth OfficialLoginAuthCloudDto
     */
    @GetMapping("/checkAuthorizationStatus")
    @ApiOperation(value = "公众号授权登陆页面URL", authorizations = {@Authorization("com.youkeyi.ddy.cloud.common.api.application.system.login.SystemOfficialLoginFeignService.checkAuthorizationStatus")})
    @ApiResponse(code = 200, message = "data Property in Response Body", response = AppletLoginAuthCloudDto.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "state", paramType = "query"),
    })
    public abstract OfficialLoginAuthCloudDto checkAuthorizationStatus(@RequestParam String state);

    /**
     * 微信小程序授权登陆轮询.
     *
     * @return the auth OfficialLoginAuthCloudDto
     */
    @GetMapping("/handleCallback")
    @ApiOperation(value = "公众号授权登陆页面URL", authorizations = {@Authorization("com.youkeyi.ddy.cloud.common.api.application.system.login.SystemOfficialLoginFeignService.handleCallback")})
    @ApiResponse(code = 200, message = "data Property in Response Body", response = ResponseContent.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", paramType = "query"),
            @ApiImplicitParam(name = "state", paramType = "query"),
    })
    public abstract ResponseContent handleCallback(@RequestParam String code,@RequestParam String state);

    /**
     * 微信公众号获取的unionid 和openid 绑定手机号.
     *
     * @return ResponseContent
     */
    @GetMapping("/bindUserByPhoneAndOpenidAndUnionId")
    @ApiOperation(value = "公众号授权登陆页面URL", authorizations = {@Authorization("com.youkeyi.ddy.cloud.common.api.application.system.login.SystemOfficialLoginFeignService.bindUserByPhoneAndOpenidAndUnionId")})
    @ApiResponse(code = 200, message = "data Property in Response Body", response = ResponseContent.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", paramType = "query"),
            @ApiImplicitParam(name = "unionId", paramType = "query"),
            @ApiImplicitParam(name = "openId", paramType = "query"),
    })
    public abstract ResponseContent bindUserByPhoneAndOpenidAndUnionId(@RequestParam String phone,@RequestParam String unionId, @RequestParam String openId);

    /**
     * 获取Token.
     *
     * @param param the param
     * @return the response content
     */
    @GetMapping(value = "/getToken")
    @ApiOperation(value = "获取Token", authorizations = {@Authorization("com.youkeyi.ddy.cloud.common.api.application.system.login.SystemOfficialLoginFeignService.getToken")})
    @ApiResponse(code = 200, message = "data Property in Response Body", response = ResponseObjectContent.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "param", paramType = "body"),
    })
    public abstract ResponseObjectContent getToken(OfficialLoginAuthCloudParam param);

    /**
     * 退出登陆.
     *
     * @return the response content
     */
    @PostMapping(value = "/logout")
    @ApiOperation(value = "退出登陆", authorizations = {@Authorization("com.youkeyi.ddy.cloud.common.api.application.system.login.SystemOfficialLoginFeignService.logout")})
    @ApiResponse(code = 200, message = "data Property in Response Body", response = ResponseContent.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "param", paramType = "query"),
    })
    public abstract ResponseContent logout(HttpServletRequest request, HttpServletResponse response);

    /**
     * 微信公众号签名获取.
     * @return Map<String, String>
     */
    @GetMapping(value = "/getWebChatConfigSign")
    @ApiOperation(value = "微信公众号签名获取", authorizations = {@Authorization("com.youkeyi.ddy.cloud.common.api.application.system.login.SystemOfficialLoginFeignService.getWeChatOfficialConfig")})
    @ApiResponse(code = 200, message = "data Property in Response Body", response = ResponseObjectContent.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "param", paramType = "body"),
    })
    public abstract ResponseObjectContent getWeChatOfficialConfig(@RequestParam String url);

}
